package
{
	import flash.events.*;
	import flash.net.Socket;

	public class FBSocket
	{
		protected var socket:Socket
		protected var fDebug:Function = null;
		public function FBSocket(fdebug:Function)
		{
			socket = new Socket();
			fDebug = fdebug;
		}
		public function Connect(url:String, port:int):void
		{
			socket.addEventListener(Event.CLOSE, closeHandler);
			socket.addEventListener(Event.CONNECT, connectHandler);
			socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
			socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
			socket.connect(url,port);
		}
		private function closeHandler(event:Event):void {
			trace("closeHandler: " + event);
			//trace(response.toString());
			if(fDebug != null) fDebug("closeHandler: " + event);
		}
		
		private function connectHandler(event:Event):void {
			trace("connectHandler: " + event);
			//sendRequest();
			if(fDebug != null) fDebug("connectHandler: " + event);
		}
		
		private function ioErrorHandler(event:IOErrorEvent):void {
			trace("ioErrorHandler: " + event);
			if(fDebug != null) fDebug("ioErrorHandler: " + event);
		}
		
		private function securityErrorHandler(event:SecurityErrorEvent):void {
			trace("securityErrorHandler: " + event);
			if(fDebug != null) fDebug("securityErrorHandler: " + event);
		}
		
		private function socketDataHandler(event:ProgressEvent):void {
			trace("socketDataHandler: " + event);
			if(fDebug != null) fDebug("socketDataHandler: " + event);
			//readResponse();
		}

	}
	
}